<html>
<script language='javascript'>
var statesExample = [
	{'stateId':'1', 'stateName': 'State 1', 'cities':[
		{'cityId': '1', 'cityName': 'City 1'}
	]},
	{'stateId':'2', 'stateName': 'State 2', 'cities':[
		{'cityId': '2', 'cityName': 'City 2'},
		{'cityId': '3', 'cityName': 'City 3'}
	]},
];
var citiesMalaysia = [];
var statesMalaysia = [{"stateId" : "1", "stateName" : "Johor", "cities" : [{"cityId" : "1", "cityName" : "Ayer Baloi", "state" : "Johor"},{"cityId" : "2", "cityName" : "Ayer Hitam", "state" : "Johor"},{"cityId" : "3", "cityName" : "Ayer Tawar 2", "state" : "Johor"},{"cityId" : "4", "cityName" : "Ayer Tawar 3", "state" : "Johor"},{"cityId" : "5", "cityName" : "Ayer Tawar 4", "state" : "Johor"},{"cityId" : "6", "cityName" : "Ayer Tawar 5", "state" : "Johor"},{"cityId" : "7", "cityName" : "Bandar Penawar", "state" : "Johor"},{"cityId" : "8", "cityName" : "Bandar Tenggara", "state" : "Johor"},{"cityId" : "9", "cityName" : "Batu Anam", "state" : "Johor"},{"cityId" : "10", "cityName" : "Batu Pahat", "state" : "Johor"},{"cityId" : "11", "cityName" : "Bekok", "state" : "Johor"},{"cityId" : "12", "cityName" : "Benut", "state" : "Johor"},{"cityId" : "13", "cityName" : "Bukit Gambir", "state" : "Johor"},{"cityId" : "14", "cityName" : "Bukit Pasir", "state" : "Johor"},{"cityId" : "15", "cityName" : "Chaah", "state" : "Johor"},{"cityId" : "16", "cityName" : "Endau", "state" : "Johor"},{"cityId" : "17", "cityName" : "Gelang Patah", "state" : "Johor"},{"cityId" : "18", "cityName" : "Gerisek", "state" : "Johor"},{"cityId" : "19", "cityName" : "Gugusan Taib Andak", "state" : "Johor"},{"cityId" : "20", "cityName" : "Jementah", "state" : "Johor"},{"cityId" : "21", "cityName" : "Johor Bahru", "state" : "Johor"},{"cityId" : "22", "cityName" : "Kahang", "state" : "Johor"},{"cityId" : "23", "cityName" : "Kluang", "state" : "Johor"},{"cityId" : "24", "cityName" : "Kota Tinggi", "state" : "Johor"},{"cityId" : "25", "cityName" : "Kukup", "state" : "Johor"},{"cityId" : "26", "cityName" : "Kulai", "state" : "Johor"},{"cityId" : "27", "cityName" : "Labis", "state" : "Johor"},{"cityId" : "28", "cityName" : "Layang-Layang", "state" : "Johor"},{"cityId" : "29", "cityName" : "Masai", "state" : "Johor"},{"cityId" : "30", "cityName" : "Mersing", "state" : "Johor"},{"cityId" : "31", "cityName" : "Muar", "state" : "Johor"},{"cityId" : "32", "cityName" : "Nusajaya", "state" : "Johor"},{"cityId" : "33", "cityName" : "Pagoh", "state" : "Johor"},{"cityId" : "34", "cityName" : "Paloh", "state" : "Johor"},{"cityId" : "35", "cityName" : "Panchor", "state" : "Johor"},{"cityId" : "36", "cityName" : "Parit Jawa", "state" : "Johor"},{"cityId" : "37", "cityName" : "Parit Raja", "state" : "Johor"},{"cityId" : "38", "cityName" : "Parit Sulong", "state" : "Johor"},{"cityId" : "39", "cityName" : "Pasir Gudang", "state" : "Johor"},{"cityId" : "40", "cityName" : "Pekan Nenas", "state" : "Johor"},{"cityId" : "41", "cityName" : "Pengerang", "state" : "Johor"},{"cityId" : "42", "cityName" : "Pontian", "state" : "Johor"},{"cityId" : "43", "cityName" : "Rengam", "state" : "Johor"},{"cityId" : "44", "cityName" : "Rengit", "state" : "Johor"},{"cityId" : "45", "cityName" : "Segamat", "state" : "Johor"},{"cityId" : "46", "cityName" : "Semerah", "state" : "Johor"},{"cityId" : "47", "cityName" : "Senai", "state" : "Johor"},{"cityId" : "48", "cityName" : "Senggarang", "state" : "Johor"},{"cityId" : "49", "cityName" : "Seri Gading", "state" : "Johor"},{"cityId" : "50", "cityName" : "Seri Medan", "state" : "Johor"},{"cityId" : "51", "cityName" : "Simpang Rengam", "state" : "Johor"},{"cityId" : "52", "cityName" : "Sri Gading", "state" : "Johor"},{"cityId" : "53", "cityName" : "Sri Medan", "state" : "Johor"},{"cityId" : "54", "cityName" : "Sungai Mati", "state" : "Johor"},{"cityId" : "55", "cityName" : "Tangkak", "state" : "Johor"},{"cityId" : "56", "cityName" : "Pulau Tioman", "state" : "Johor"},{"cityId" : "57", "cityName" : "Ulu Tiram", "state" : "Johor"},{"cityId" : "58", "cityName" : "Yong Peng", "state" : "Johor"},{"cityId" : "458", "cityName" : "Johor", "state" : "Johor"}]},{"stateId" : "2", "stateName" : "Kedah", "cities" : [{"cityId" : "59", "cityName" : "Alor Setar", "state" : "Kedah"},{"cityId" : "60", "cityName" : "Ayer Hitam", "state" : "Kedah"},{"cityId" : "61", "cityName" : "Baling", "state" : "Kedah"},{"cityId" : "62", "cityName" : "Bandar Baharu", "state" : "Kedah"},{"cityId" : "63", "cityName" : "Bedong", "state" : "Kedah"},{"cityId" : "64", "cityName" : "Bukit Kayu Hitam", "state" : "Kedah"},{"cityId" : "65", "cityName" : "Changloon", "state" : "Kedah"},{"cityId" : "66", "cityName" : "Gurun", "state" : "Kedah"},{"cityId" : "67", "cityName" : "Jeniang", "state" : "Kedah"},{"cityId" : "68", "cityName" : "Jitra", "state" : "Kedah"},{"cityId" : "69", "cityName" : "Karangan", "state" : "Kedah"},{"cityId" : "70", "cityName" : "Kepala Batas", "state" : "Kedah"},{"cityId" : "71", "cityName" : "Kodiang", "state" : "Kedah"},{"cityId" : "72", "cityName" : "Kota Kuala Muda", "state" : "Kedah"},{"cityId" : "73", "cityName" : "Kota Sarang Semut", "state" : "Kedah"},{"cityId" : "74", "cityName" : "Kuala Kedah", "state" : "Kedah"},{"cityId" : "75", "cityName" : "Kuala Ketil", "state" : "Kedah"},{"cityId" : "76", "cityName" : "Kuala Nerang", "state" : "Kedah"},{"cityId" : "77", "cityName" : "Kuala Pegang", "state" : "Kedah"},{"cityId" : "78", "cityName" : "Kulim", "state" : "Kedah"},{"cityId" : "79", "cityName" : "Kupang", "state" : "Kedah"},{"cityId" : "80", "cityName" : "Langgar", "state" : "Kedah"},{"cityId" : "81", "cityName" : "Langkawi", "state" : "Kedah"},{"cityId" : "82", "cityName" : "Lunas", "state" : "Kedah"},{"cityId" : "83", "cityName" : "Merbok", "state" : "Kedah"},{"cityId" : "84", "cityName" : "Padang Serai", "state" : "Kedah"},{"cityId" : "85", "cityName" : "Pendang", "state" : "Kedah"},{"cityId" : "86", "cityName" : "Pokok Sena", "state" : "Kedah"},{"cityId" : "87", "cityName" : "Serdang", "state" : "Kedah"},{"cityId" : "88", "cityName" : "Sik", "state" : "Kedah"},{"cityId" : "89", "cityName" : "Simpang Empat", "state" : "Kedah"},{"cityId" : "90", "cityName" : "Sungai Petani", "state" : "Kedah"},{"cityId" : "91", "cityName" : "Universiti Utara Malaysia", "state" : "Kedah"},{"cityId" : "92", "cityName" : "Yan", "state" : "Kedah"},{"cityId" : "459", "cityName" : "Kedah", "state" : "Kedah"}]},{"stateId" : "3", "stateName" : "Kelantan", "cities" : [{"cityId" : "93", "cityName" : "Ayer Lanas", "state" : "Kelantan"},{"cityId" : "94", "cityName" : "Bachok", "state" : "Kelantan"},{"cityId" : "95", "cityName" : "Cherang Ruku", "state" : "Kelantan"},{"cityId" : "96", "cityName" : "Dabong", "state" : "Kelantan"},{"cityId" : "97", "cityName" : "Gua Musang", "state" : "Kelantan"},{"cityId" : "98", "cityName" : "Jeli", "state" : "Kelantan"},{"cityId" : "99", "cityName" : "Kem Desa Pahlawan", "state" : "Kelantan"},{"cityId" : "100", "cityName" : "Ketereh", "state" : "Kelantan"},{"cityId" : "101", "cityName" : "Kota Bahru", "state" : "Kelantan"},{"cityId" : "102", "cityName" : "Kota Bharu", "state" : "Kelantan"},{"cityId" : "103", "cityName" : "Kuala Balah", "state" : "Kelantan"},{"cityId" : "104", "cityName" : "Kuala Krai", "state" : "Kelantan"},{"cityId" : "105", "cityName" : "Kubang Kerian", "state" : "Kelantan"},{"cityId" : "106", "cityName" : "Machang", "state" : "Kelantan"},{"cityId" : "107", "cityName" : "Melor", "state" : "Kelantan"},{"cityId" : "108", "cityName" : "Pasir Mas", "state" : "Kelantan"},{"cityId" : "109", "cityName" : "Pasir Puteh", "state" : "Kelantan"},{"cityId" : "110", "cityName" : "Pulai Chondong", "state" : "Kelantan"},{"cityId" : "111", "cityName" : "Rantau Panjang", "state" : "Kelantan"},{"cityId" : "112", "cityName" : "Selising", "state" : "Kelantan"},{"cityId" : "113", "cityName" : "Tanah Merah", "state" : "Kelantan"},{"cityId" : "114", "cityName" : "Temangan", "state" : "Kelantan"},{"cityId" : "115", "cityName" : "Tumpat", "state" : "Kelantan"},{"cityId" : "116", "cityName" : "Wakaf Bharu", "state" : "Kelantan"},{"cityId" : "460", "cityName" : "Kelantan", "state" : "Kelantan"}]},{"stateId" : "4", "stateName" : "WP Kuala Lumpur", "cities" : [{"cityId" : "453", "cityName" : "Batu Caves", "state" : "WP Kuala Lumpur"},{"cityId" : "454", "cityName" : "Kuala Lumpur", "state" : "WP Kuala Lumpur"},{"cityId" : "455", "cityName" : "Setapak", "state" : "WP Kuala Lumpur"}]},{"stateId" : "5", "stateName" : "Melaka", "cities" : [{"cityId" : "117", "cityName" : "Alor Gajah", "state" : "Melaka"},{"cityId" : "118", "cityName" : "Asahan", "state" : "Melaka"},{"cityId" : "119", "cityName" : "Ayer Keroh", "state" : "Melaka"},{"cityId" : "120", "cityName" : "Bemban", "state" : "Melaka"},{"cityId" : "121", "cityName" : "Durian Tunggal", "state" : "Melaka"},{"cityId" : "122", "cityName" : "Jasin", "state" : "Melaka"},{"cityId" : "123", "cityName" : "Kem Trendak", "state" : "Melaka"},{"cityId" : "124", "cityName" : "Kuala Sungai Baru", "state" : "Melaka"},{"cityId" : "125", "cityName" : "Lubok China", "state" : "Melaka"},{"cityId" : "126", "cityName" : "Masjid Tanah", "state" : "Melaka"},{"cityId" : "127", "cityName" : "Melaka", "state" : "Melaka"},{"cityId" : "128", "cityName" : "Merlimau", "state" : "Melaka"},{"cityId" : "129", "cityName" : "Selandar", "state" : "Melaka"},{"cityId" : "130", "cityName" : "Sungai Rambai", "state" : "Melaka"},{"cityId" : "131", "cityName" : "Sungai Udang", "state" : "Melaka"},{"cityId" : "132", "cityName" : "Tanjong Kling", "state" : "Melaka"},{"cityId" : "461", "cityName" : "Melaka", "state" : "Melaka"}]},{"stateId" : "6", "stateName" : "Negeri Sembilan", "cities" : [{"cityId" : "133", "cityName" : "Bahau", "state" : "Negeri Sembilan"},{"cityId" : "134", "cityName" : "Bandar Baru Enstek", "state" : "Negeri Sembilan"},{"cityId" : "135", "cityName" : "Bandar Seri Jempol", "state" : "Negeri Sembilan"},{"cityId" : "136", "cityName" : "Batu Kikir", "state" : "Negeri Sembilan"},{"cityId" : "137", "cityName" : "Gemas", "state" : "Negeri Sembilan"},{"cityId" : "138", "cityName" : "Gemencheh", "state" : "Negeri Sembilan"},{"cityId" : "139", "cityName" : "Johol", "state" : "Negeri Sembilan"},{"cityId" : "140", "cityName" : "Kota", "state" : "Negeri Sembilan"},{"cityId" : "141", "cityName" : "Kuala Klawang", "state" : "Negeri Sembilan"},{"cityId" : "142", "cityName" : "Kuala Pilah", "state" : "Negeri Sembilan"},{"cityId" : "143", "cityName" : "Labu", "state" : "Negeri Sembilan"},{"cityId" : "144", "cityName" : "Linggi", "state" : "Negeri Sembilan"},{"cityId" : "145", "cityName" : "Mantin", "state" : "Negeri Sembilan"},{"cityId" : "146", "cityName" : "Nilai", "state" : "Negeri Sembilan"},{"cityId" : "147", "cityName" : "Port Dickson", "state" : "Negeri Sembilan"},{"cityId" : "148", "cityName" : "Pusat  Bandar Palong", "state" : "Negeri Sembilan"},{"cityId" : "149", "cityName" : "Rantau", "state" : "Negeri Sembilan"},{"cityId" : "150", "cityName" : "Rembau", "state" : "Negeri Sembilan"},{"cityId" : "151", "cityName" : "Rompin", "state" : "Negeri Sembilan"},{"cityId" : "152", "cityName" : "Seremban", "state" : "Negeri Sembilan"},{"cityId" : "153", "cityName" : "Si Rusa", "state" : "Negeri Sembilan"},{"cityId" : "154", "cityName" : "Simpang Durian", "state" : "Negeri Sembilan"},{"cityId" : "155", "cityName" : "Simpang Pertang", "state" : "Negeri Sembilan"},{"cityId" : "156", "cityName" : "Tampin", "state" : "Negeri Sembilan"},{"cityId" : "157", "cityName" : "Tanjong Ipoh", "state" : "Negeri Sembilan"},{"cityId" : "462", "cityName" : "Negeri Sembilan", "state" : "Negeri Sembilan"}]},{"stateId" : "7", "stateName" : "Pahang", "cities" : [{"cityId" : "158", "cityName" : "Balok", "state" : "Pahang"},{"cityId" : "159", "cityName" : "Bandar Bera", "state" : "Pahang"},{"cityId" : "160", "cityName" : "Bandar Pusat Jengka", "state" : "Pahang"},{"cityId" : "161", "cityName" : "Bandar Tun Abdul Razak", "state" : "Pahang"},{"cityId" : "162", "cityName" : "Benta", "state" : "Pahang"},{"cityId" : "163", "cityName" : "Bentong", "state" : "Pahang"},{"cityId" : "164", "cityName" : "Brinchang", "state" : "Pahang"},{"cityId" : "165", "cityName" : "Bukit Fraser", "state" : "Pahang"},{"cityId" : "166", "cityName" : "Bukit Goh", "state" : "Pahang"},{"cityId" : "167", "cityName" : "Chenor", "state" : "Pahang"},{"cityId" : "168", "cityName" : "Chini", "state" : "Pahang"},{"cityId" : "169", "cityName" : "Damak", "state" : "Pahang"},{"cityId" : "170", "cityName" : "Dong", "state" : "Pahang"},{"cityId" : "171", "cityName" : "Gambang", "state" : "Pahang"},{"cityId" : "172", "cityName" : "Genting Highlands", "state" : "Pahang"},{"cityId" : "173", "cityName" : "Jaya Gading", "state" : "Pahang"},{"cityId" : "174", "cityName" : "Jerantut", "state" : "Pahang"},{"cityId" : "175", "cityName" : "Karak", "state" : "Pahang"},{"cityId" : "176", "cityName" : "Kemayan", "state" : "Pahang"},{"cityId" : "177", "cityName" : "Kuala Krau", "state" : "Pahang"},{"cityId" : "178", "cityName" : "Kuala Lipis", "state" : "Pahang"},{"cityId" : "179", "cityName" : "Kuala Rompin", "state" : "Pahang"},{"cityId" : "180", "cityName" : "Kuantan", "state" : "Pahang"},{"cityId" : "181", "cityName" : "Lanchang", "state" : "Pahang"},{"cityId" : "182", "cityName" : "Lurah Bilut", "state" : "Pahang"},{"cityId" : "183", "cityName" : "Maran", "state" : "Pahang"},{"cityId" : "184", "cityName" : "Mentakab", "state" : "Pahang"},{"cityId" : "185", "cityName" : "Muadzam Shah", "state" : "Pahang"},{"cityId" : "186", "cityName" : "Padang Tengku", "state" : "Pahang"},{"cityId" : "187", "cityName" : "Pekan", "state" : "Pahang"},{"cityId" : "188", "cityName" : "Raub", "state" : "Pahang"},{"cityId" : "189", "cityName" : "Ringlet", "state" : "Pahang"},{"cityId" : "190", "cityName" : "Sega", "state" : "Pahang"},{"cityId" : "191", "cityName" : "Sungai Koyan", "state" : "Pahang"},{"cityId" : "192", "cityName" : "Sungai Lembing", "state" : "Pahang"},{"cityId" : "193", "cityName" : "Sungai Ruan", "state" : "Pahang"},{"cityId" : "194", "cityName" : "Tanah Rata", "state" : "Pahang"},{"cityId" : "195", "cityName" : "Temerloh", "state" : "Pahang"},{"cityId" : "196", "cityName" : "Triang", "state" : "Pahang"},{"cityId" : "463", "cityName" : "Pahang", "state" : "Pahang"}]},{"stateId" : "8", "stateName" : "Perak", "cities" : [{"cityId" : "197", "cityName" : "Ayer Tawar", "state" : "Perak"},{"cityId" : "198", "cityName" : "Bagan Datoh", "state" : "Perak"},{"cityId" : "199", "cityName" : "Bagan Serai", "state" : "Perak"},{"cityId" : "200", "cityName" : "Bandar Seri Iskandar", "state" : "Perak"},{"cityId" : "201", "cityName" : "Batu Gajah", "state" : "Perak"},{"cityId" : "202", "cityName" : "Batu Kurau", "state" : "Perak"},{"cityId" : "203", "cityName" : "Behrang Stesen", "state" : "Perak"},{"cityId" : "204", "cityName" : "Bidor", "state" : "Perak"},{"cityId" : "205", "cityName" : "Bota", "state" : "Perak"},{"cityId" : "206", "cityName" : "Bruas", "state" : "Perak"},{"cityId" : "207", "cityName" : "Changkat Jering", "state" : "Perak"},{"cityId" : "208", "cityName" : "Changkat Keruing", "state" : "Perak"},{"cityId" : "209", "cityName" : "Chemor", "state" : "Perak"},{"cityId" : "210", "cityName" : "Chenderiang", "state" : "Perak"},{"cityId" : "211", "cityName" : "Chenderong Balai", "state" : "Perak"},{"cityId" : "212", "cityName" : "Chikus", "state" : "Perak"},{"cityId" : "213", "cityName" : "Enggor", "state" : "Perak"},{"cityId" : "214", "cityName" : "Gerik", "state" : "Perak"},{"cityId" : "215", "cityName" : "Gopeng", "state" : "Perak"},{"cityId" : "216", "cityName" : "Hutan Melintang", "state" : "Perak"},{"cityId" : "217", "cityName" : "Intan", "state" : "Perak"},{"cityId" : "218", "cityName" : "Ipoh", "state" : "Perak"},{"cityId" : "219", "cityName" : "Jeram", "state" : "Perak"},{"cityId" : "220", "cityName" : "Kampar", "state" : "Perak"},{"cityId" : "221", "cityName" : "Kampung Gajah", "state" : "Perak"},{"cityId" : "222", "cityName" : "Kampung Kepayang", "state" : "Perak"},{"cityId" : "223", "cityName" : "Kamunting", "state" : "Perak"},{"cityId" : "224", "cityName" : "Kuala Kangsar", "state" : "Perak"},{"cityId" : "225", "cityName" : "Kuala Kurau", "state" : "Perak"},{"cityId" : "226", "cityName" : "Kuala Sepetang", "state" : "Perak"},{"cityId" : "227", "cityName" : "Lambor Kanan", "state" : "Perak"},{"cityId" : "228", "cityName" : "Langkap", "state" : "Perak"},{"cityId" : "229", "cityName" : "Lenggong", "state" : "Perak"},{"cityId" : "230", "cityName" : "Lumut", "state" : "Perak"},{"cityId" : "231", "cityName" : "Malim Nawar", "state" : "Perak"},{"cityId" : "232", "cityName" : "Mambang Di Awan", "state" : "Perak"},{"cityId" : "233", "cityName" : "Manong", "state" : "Perak"},{"cityId" : "234", "cityName" : "Matang", "state" : "Perak"},{"cityId" : "235", "cityName" : "Padang Rengas", "state" : "Perak"},{"cityId" : "236", "cityName" : "Pangkor", "state" : "Perak"},{"cityId" : "237", "cityName" : "Pantai Remis", "state" : "Perak"},{"cityId" : "238", "cityName" : "Parit", "state" : "Perak"},{"cityId" : "239", "cityName" : "Parit Buntar", "state" : "Perak"},{"cityId" : "240", "cityName" : "Pengkalan Hulu", "state" : "Perak"},{"cityId" : "241", "cityName" : "Pusing", "state" : "Perak"},{"cityId" : "242", "cityName" : "Rantau Panjang", "state" : "Perak"},{"cityId" : "243", "cityName" : "Sauk", "state" : "Perak"},{"cityId" : "244", "cityName" : "Selama", "state" : "Perak"},{"cityId" : "245", "cityName" : "Selekoh", "state" : "Perak"},{"cityId" : "246", "cityName" : "Seri Manjong", "state" : "Perak"},{"cityId" : "247", "cityName" : "Seri Manjung", "state" : "Perak"},{"cityId" : "248", "cityName" : "Simpang", "state" : "Perak"},{"cityId" : "249", "cityName" : "Simpang Ampat Semanggol", "state" : "Perak"},{"cityId" : "250", "cityName" : "Sitiawan", "state" : "Perak"},{"cityId" : "251", "cityName" : "Slim River", "state" : "Perak"},{"cityId" : "252", "cityName" : "Sungai Siput", "state" : "Perak"},{"cityId" : "253", "cityName" : "Sungai Sumun", "state" : "Perak"},{"cityId" : "254", "cityName" : "Sungkai", "state" : "Perak"},{"cityId" : "255", "cityName" : "TLDM Lumut", "state" : "Perak"},{"cityId" : "256", "cityName" : "Taiping", "state" : "Perak"},{"cityId" : "257", "cityName" : "Tanjong Malim", "state" : "Perak"},{"cityId" : "258", "cityName" : "Tanjong Piandang", "state" : "Perak"},{"cityId" : "259", "cityName" : "Tanjong Rambutan", "state" : "Perak"},{"cityId" : "260", "cityName" : "Tanjong Tualang", "state" : "Perak"},{"cityId" : "261", "cityName" : "Tapah", "state" : "Perak"},{"cityId" : "262", "cityName" : "Tapah Road", "state" : "Perak"},{"cityId" : "263", "cityName" : "Teluk Intan", "state" : "Perak"},{"cityId" : "264", "cityName" : "Temoh", "state" : "Perak"},{"cityId" : "265", "cityName" : "Trolak", "state" : "Perak"},{"cityId" : "266", "cityName" : "Trong", "state" : "Perak"},{"cityId" : "267", "cityName" : "Tronoh", "state" : "Perak"},{"cityId" : "268", "cityName" : "Ulu Bernam", "state" : "Perak"},{"cityId" : "269", "cityName" : "Ulu Kinta", "state" : "Perak"},{"cityId" : "464", "cityName" : "Perak", "state" : "Perak"}]},{"stateId" : "9", "stateName" : "Perlis", "cities" : [{"cityId" : "270", "cityName" : "Arau", "state" : "Perlis"},{"cityId" : "271", "cityName" : "Kaki Bukit", "state" : "Perlis"},{"cityId" : "272", "cityName" : "Kangar", "state" : "Perlis"},{"cityId" : "273", "cityName" : "Kuala Perlis", "state" : "Perlis"},{"cityId" : "274", "cityName" : "Padang Besar", "state" : "Perlis"},{"cityId" : "275", "cityName" : "Simpang Ampat", "state" : "Perlis"},{"cityId" : "465", "cityName" : "Perlis", "state" : "Perlis"}]},{"stateId" : "10", "stateName" : "Pulau Pinang", "cities" : [{"cityId" : "276", "cityName" : "Ayer Itam", "state" : "Pulau Pinang"},{"cityId" : "277", "cityName" : "Balik Pulau", "state" : "Pulau Pinang"},{"cityId" : "278", "cityName" : "Batu Ferringhi", "state" : "Pulau Pinang"},{"cityId" : "279", "cityName" : "Batu Maung", "state" : "Pulau Pinang"},{"cityId" : "280", "cityName" : "Bayan Lepas", "state" : "Pulau Pinang"},{"cityId" : "281", "cityName" : "Bukit Mertajam", "state" : "Pulau Pinang"},{"cityId" : "282", "cityName" : "Butterworth", "state" : "Pulau Pinang"},{"cityId" : "283", "cityName" : "Gelugor", "state" : "Pulau Pinang"},{"cityId" : "284", "cityName" : "Jelutong", "state" : "Pulau Pinang"},{"cityId" : "285", "cityName" : "Kepala Batas", "state" : "Pulau Pinang"},{"cityId" : "286", "cityName" : "Kubang Semang", "state" : "Pulau Pinang"},{"cityId" : "287", "cityName" : "Nibong Tebal", "state" : "Pulau Pinang"},{"cityId" : "288", "cityName" : "Padang Tembak", "state" : "Pulau Pinang"},{"cityId" : "289", "cityName" : "Penaga", "state" : "Pulau Pinang"},{"cityId" : "290", "cityName" : "Penang Hill", "state" : "Pulau Pinang"},{"cityId" : "291", "cityName" : "Perai", "state" : "Pulau Pinang"},{"cityId" : "292", "cityName" : "Permatang Pauh", "state" : "Pulau Pinang"},{"cityId" : "293", "cityName" : "Pulau Pinang", "state" : "Pulau Pinang"},{"cityId" : "294", "cityName" : "Simpang Ampat", "state" : "Pulau Pinang"},{"cityId" : "295", "cityName" : "Sungai Jawi", "state" : "Pulau Pinang"},{"cityId" : "296", "cityName" : "Tanjong Bungah", "state" : "Pulau Pinang"},{"cityId" : "297", "cityName" : "Tasek Gelugor", "state" : "Pulau Pinang"},{"cityId" : "298", "cityName" : "USM Pulau Pinang", "state" : "Pulau Pinang"},{"cityId" : "466", "cityName" : "Pulau Pinang", "state" : "Pulau Pinang"}]},{"stateId" : "11", "stateName" : "WP Putrajaya", "cities" : [{"cityId" : "457", "cityName" : "Putrajaya", "state" : "WP Putrajaya"}]},{"stateId" : "12", "stateName" : "Sabah", "cities" : [{"cityId" : "299", "cityName" : "Beaufort", "state" : "Sabah"},{"cityId" : "300", "cityName" : "Beluran", "state" : "Sabah"},{"cityId" : "301", "cityName" : "Beverly", "state" : "Sabah"},{"cityId" : "302", "cityName" : "Bongawan", "state" : "Sabah"},{"cityId" : "303", "cityName" : "Inanam", "state" : "Sabah"},{"cityId" : "304", "cityName" : "Keningau", "state" : "Sabah"},{"cityId" : "305", "cityName" : "Kota Belud", "state" : "Sabah"},{"cityId" : "306", "cityName" : "Kota Kinabalu", "state" : "Sabah"},{"cityId" : "307", "cityName" : "Kota Kinabatangan", "state" : "Sabah"},{"cityId" : "308", "cityName" : "Kota Marudu", "state" : "Sabah"},{"cityId" : "309", "cityName" : "Kuala Penyu", "state" : "Sabah"},{"cityId" : "310", "cityName" : "Kudat", "state" : "Sabah"},{"cityId" : "311", "cityName" : "Kunak", "state" : "Sabah"},{"cityId" : "312", "cityName" : "Lahad Datu", "state" : "Sabah"},{"cityId" : "313", "cityName" : "Likas", "state" : "Sabah"},{"cityId" : "314", "cityName" : "Membakut", "state" : "Sabah"},{"cityId" : "315", "cityName" : "Menumbok", "state" : "Sabah"},{"cityId" : "316", "cityName" : "Nabawan", "state" : "Sabah"},{"cityId" : "317", "cityName" : "Pamol", "state" : "Sabah"},{"cityId" : "318", "cityName" : "Papar", "state" : "Sabah"},{"cityId" : "319", "cityName" : "Penampang", "state" : "Sabah"},{"cityId" : "320", "cityName" : "Putatan", "state" : "Sabah"},{"cityId" : "321", "cityName" : "Ranau", "state" : "Sabah"},{"cityId" : "322", "cityName" : "Sandakan", "state" : "Sabah"},{"cityId" : "323", "cityName" : "Semporna", "state" : "Sabah"},{"cityId" : "324", "cityName" : "Sipitang", "state" : "Sabah"},{"cityId" : "325", "cityName" : "Tambunan", "state" : "Sabah"},{"cityId" : "326", "cityName" : "Tamparuli", "state" : "Sabah"},{"cityId" : "327", "cityName" : "Tanjung Aru", "state" : "Sabah"},{"cityId" : "328", "cityName" : "Tawau", "state" : "Sabah"},{"cityId" : "329", "cityName" : "Tenghilan", "state" : "Sabah"},{"cityId" : "330", "cityName" : "Tenom", "state" : "Sabah"},{"cityId" : "331", "cityName" : "Tuaran", "state" : "Sabah"},{"cityId" : "467", "cityName" : "Sabah", "state" : "Sabah"}]},{"stateId" : "13", "stateName" : "Sarawak", "cities" : [{"cityId" : "332", "cityName" : "Asajaya", "state" : "Sarawak"},{"cityId" : "333", "cityName" : "Balingian", "state" : "Sarawak"},{"cityId" : "334", "cityName" : "Baram", "state" : "Sarawak"},{"cityId" : "335", "cityName" : "Bau", "state" : "Sarawak"},{"cityId" : "336", "cityName" : "Bekenu", "state" : "Sarawak"},{"cityId" : "337", "cityName" : "Belaga", "state" : "Sarawak"},{"cityId" : "338", "cityName" : "Belawai", "state" : "Sarawak"},{"cityId" : "339", "cityName" : "Betong", "state" : "Sarawak"},{"cityId" : "340", "cityName" : "Bintangor", "state" : "Sarawak"},{"cityId" : "341", "cityName" : "Bintulu", "state" : "Sarawak"},{"cityId" : "342", "cityName" : "Dalat", "state" : "Sarawak"},{"cityId" : "343", "cityName" : "Daro", "state" : "Sarawak"},{"cityId" : "344", "cityName" : "Debak", "state" : "Sarawak"},{"cityId" : "345", "cityName" : "Engkilili", "state" : "Sarawak"},{"cityId" : "346", "cityName" : "Julau", "state" : "Sarawak"},{"cityId" : "347", "cityName" : "Kabong", "state" : "Sarawak"},{"cityId" : "348", "cityName" : "Kanowit", "state" : "Sarawak"},{"cityId" : "349", "cityName" : "Kapit", "state" : "Sarawak"},{"cityId" : "350", "cityName" : "Kota Samarahan", "state" : "Sarawak"},{"cityId" : "351", "cityName" : "Kuching", "state" : "Sarawak"},{"cityId" : "352", "cityName" : "Lawas", "state" : "Sarawak"},{"cityId" : "353", "cityName" : "Limbang", "state" : "Sarawak"},{"cityId" : "354", "cityName" : "Lingga", "state" : "Sarawak"},{"cityId" : "355", "cityName" : "Long Lama", "state" : "Sarawak"},{"cityId" : "356", "cityName" : "Lubok Antu", "state" : "Sarawak"},{"cityId" : "357", "cityName" : "Lundu", "state" : "Sarawak"},{"cityId" : "358", "cityName" : "Lutong", "state" : "Sarawak"},{"cityId" : "359", "cityName" : "Matu", "state" : "Sarawak"},{"cityId" : "360", "cityName" : "Miri", "state" : "Sarawak"},{"cityId" : "361", "cityName" : "Mukah", "state" : "Sarawak"},{"cityId" : "362", "cityName" : "Nanga Medamit", "state" : "Sarawak"},{"cityId" : "363", "cityName" : "Niah", "state" : "Sarawak"},{"cityId" : "364", "cityName" : "Pusa", "state" : "Sarawak"},{"cityId" : "365", "cityName" : "Roban", "state" : "Sarawak"},{"cityId" : "366", "cityName" : "Saratok", "state" : "Sarawak"},{"cityId" : "367", "cityName" : "Sarikei", "state" : "Sarawak"},{"cityId" : "368", "cityName" : "Sebauh", "state" : "Sarawak"},{"cityId" : "369", "cityName" : "Sebuyau", "state" : "Sarawak"},{"cityId" : "370", "cityName" : "Serian", "state" : "Sarawak"},{"cityId" : "371", "cityName" : "Sibu", "state" : "Sarawak"},{"cityId" : "372", "cityName" : "Siburan", "state" : "Sarawak"},{"cityId" : "373", "cityName" : "Simunjan", "state" : "Sarawak"},{"cityId" : "374", "cityName" : "Song", "state" : "Sarawak"},{"cityId" : "375", "cityName" : "Spaoh", "state" : "Sarawak"},{"cityId" : "376", "cityName" : "Sri Aman", "state" : "Sarawak"},{"cityId" : "377", "cityName" : "Sundar", "state" : "Sarawak"},{"cityId" : "378", "cityName" : "Tatau", "state" : "Sarawak"},{"cityId" : "468", "cityName" : "Sarawak", "state" : "Sarawak"}]},{"stateId" : "14", "stateName" : "Selangor", "cities" : [{"cityId" : "379", "cityName" : "Ampang", "state" : "Selangor"},{"cityId" : "380", "cityName" : "Bandar Baru Bangi", "state" : "Selangor"},{"cityId" : "381", "cityName" : "Bandar Puncak Alam", "state" : "Selangor"},{"cityId" : "382", "cityName" : "Bangi", "state" : "Selangor"},{"cityId" : "383", "cityName" : "Banting", "state" : "Selangor"},{"cityId" : "384", "cityName" : "Batang Berjuntai", "state" : "Selangor"},{"cityId" : "385", "cityName" : "Batang Kali", "state" : "Selangor"},{"cityId" : "386", "cityName" : "Batangkali", "state" : "Selangor"},{"cityId" : "387", "cityName" : "Batu Arang", "state" : "Selangor"},{"cityId" : "388", "cityName" : "Batu Caves", "state" : "Selangor"},{"cityId" : "389", "cityName" : "Beranang", "state" : "Selangor"},{"cityId" : "390", "cityName" : "Bukit Rotan", "state" : "Selangor"},{"cityId" : "391", "cityName" : "Cheras", "state" : "Selangor"},{"cityId" : "392", "cityName" : "Cyberjaya", "state" : "Selangor"},{"cityId" : "393", "cityName" : "Dengkil", "state" : "Selangor"},{"cityId" : "394", "cityName" : "Gombak", "state" : "Selangor"},{"cityId" : "395", "cityName" : "Hulu Langat", "state" : "Selangor"},{"cityId" : "396", "cityName" : "Jenjarom", "state" : "Selangor"},{"cityId" : "397", "cityName" : "Jeram", "state" : "Selangor"},{"cityId" : "398", "cityName" : "KLIA", "state" : "Selangor"},{"cityId" : "399", "cityName" : "Kajang", "state" : "Selangor"},{"cityId" : "400", "cityName" : "Kapar", "state" : "Selangor"},{"cityId" : "401", "cityName" : "Kerling", "state" : "Selangor"},{"cityId" : "402", "cityName" : "Klang", "state" : "Selangor"},{"cityId" : "403", "cityName" : "Kuala Kubu Bharu", "state" : "Selangor"},{"cityId" : "404", "cityName" : "Kuala Selangor", "state" : "Selangor"},{"cityId" : "405", "cityName" : "Pandan", "state" : "Selangor"},{"cityId" : "406", "cityName" : "Pelabuhan Klang", "state" : "Selangor"},{"cityId" : "407", "cityName" : "Petaling Jaya", "state" : "Selangor"},{"cityId" : "408", "cityName" : "Puchong", "state" : "Selangor"},{"cityId" : "409", "cityName" : "Pulau Carey", "state" : "Selangor"},{"cityId" : "410", "cityName" : "Pulau Indah", "state" : "Selangor"},{"cityId" : "411", "cityName" : "Pulau Ketam", "state" : "Selangor"},{"cityId" : "412", "cityName" : "Rasa", "state" : "Selangor"},{"cityId" : "413", "cityName" : "Rawang", "state" : "Selangor"},{"cityId" : "414", "cityName" : "Sabak Bernam", "state" : "Selangor"},{"cityId" : "415", "cityName" : "Sekinchan", "state" : "Selangor"},{"cityId" : "416", "cityName" : "Semenyih", "state" : "Selangor"},{"cityId" : "417", "cityName" : "Sepang", "state" : "Selangor"},{"cityId" : "418", "cityName" : "Serdang", "state" : "Selangor"},{"cityId" : "419", "cityName" : "Serendah", "state" : "Selangor"},{"cityId" : "420", "cityName" : "Seri Kembangan", "state" : "Selangor"},{"cityId" : "421", "cityName" : "Shah Alam", "state" : "Selangor"},{"cityId" : "422", "cityName" : "Subang Airport", "state" : "Selangor"},{"cityId" : "423", "cityName" : "Subang Jaya", "state" : "Selangor"},{"cityId" : "424", "cityName" : "Sungai Ayer Tawar", "state" : "Selangor"},{"cityId" : "425", "cityName" : "Sungai Besar", "state" : "Selangor"},{"cityId" : "426", "cityName" : "Sungai Buloh", "state" : "Selangor"},{"cityId" : "427", "cityName" : "Sungai Pelek", "state" : "Selangor"},{"cityId" : "428", "cityName" : "Tanjong Karang", "state" : "Selangor"},{"cityId" : "429", "cityName" : "Tanjong Sepat", "state" : "Selangor"},{"cityId" : "430", "cityName" : "Telok Panglima Garang", "state" : "Selangor"},{"cityId" : "469", "cityName" : "Selangor", "state" : "Selangor"}]},{"stateId" : "15", "stateName" : "Terengganu", "cities" : [{"cityId" : "431", "cityName" : "Ajil", "state" : "Terengganu"},{"cityId" : "432", "cityName" : "Al Muktatfi Billah Shah", "state" : "Terengganu"},{"cityId" : "433", "cityName" : "Ayer Puteh", "state" : "Terengganu"},{"cityId" : "434", "cityName" : "Bukit Besi", "state" : "Terengganu"},{"cityId" : "435", "cityName" : "Bukit Payong", "state" : "Terengganu"},{"cityId" : "436", "cityName" : "Ceneh", "state" : "Terengganu"},{"cityId" : "437", "cityName" : "Chalok", "state" : "Terengganu"},{"cityId" : "438", "cityName" : "Cukai", "state" : "Terengganu"},{"cityId" : "439", "cityName" : "Dungun", "state" : "Terengganu"},{"cityId" : "440", "cityName" : "Jerteh", "state" : "Terengganu"},{"cityId" : "441", "cityName" : "Kampung Raja", "state" : "Terengganu"},{"cityId" : "442", "cityName" : "Kemasek", "state" : "Terengganu"},{"cityId" : "443", "cityName" : "Kerteh", "state" : "Terengganu"},{"cityId" : "444", "cityName" : "Ketengah Jaya", "state" : "Terengganu"},{"cityId" : "445", "cityName" : "Kijal", "state" : "Terengganu"},{"cityId" : "446", "cityName" : "Kuala Berang", "state" : "Terengganu"},{"cityId" : "447", "cityName" : "Kuala Besut", "state" : "Terengganu"},{"cityId" : "448", "cityName" : "Kuala Terengganu", "state" : "Terengganu"},{"cityId" : "449", "cityName" : "Marang", "state" : "Terengganu"},{"cityId" : "450", "cityName" : "Paka", "state" : "Terengganu"},{"cityId" : "451", "cityName" : "Permaisuri", "state" : "Terengganu"},{"cityId" : "452", "cityName" : "Sungai Tong", "state" : "Terengganu"},{"cityId" : "470", "cityName" : "Terengganu", "state" : "Terengganu"}]},{"stateId" : "16", "stateName" : "WP Labuan", "cities" : [{"cityId" : "456", "cityName" : "Labuan", "state" : "WP Labuan"}]}];

function Chainer(data, parentSelectionId, parentItemIdProp, parentItemTextProp, childrenDataProp, childSelectionId, childItemIdProp, childItemTextProp){
	var that = this;
	this.data = data;
	this.parentSelectionId = parentSelectionId;
	this.parentItemIdProp = parentItemIdProp;
	this.parentItemTextProp = parentItemTextProp;
	this.childrenDataProp = childrenDataProp;
	this.childSelectionId = childSelectionId;
	this.childItemIdProp = childItemIdProp;
	this.childItemTextProp = childItemTextProp;
	this.parentFirstItemText = '---Select an item---';
	this.childrenFirstItemText = '---Select an item---';
	this.defaultParentValue = '';
	this.defaultChildrenValue = '';
	this.init = function(defaultParentValue, defaultChildrenValue){
		document.getElementById(that.parentSelectionId).onchange = function(){that.print_children('');};
		that.resetValue(defaultParentValue, defaultChildrenValue);
	}
	this.resetValue = function(defaultParentValue, defaultChildrenValue){
		this.defaultParentValue = defaultParentValue;
		this.defaultChildrenValue = defaultChildrenValue;
		this.print_parent(this.defaultParentValue);
		this.print_children(this.defaultChildrenValue);
	}
	this.print_parent = function(currentValue){
	    print(data, this.parentSelectionId, this.parentItemIdProp, this.parentItemTextProp, currentValue, this.parentFirstItemText);
	}
	this.print_children = function(currentValue){
	    var selParent = document.getElementById(that.parentSelectionId);
	    var childrenData = {};
	    var parentIndex = selParent.selectedIndex;
	    if (that.parentFirstItemText != null) {
		parentIndex = parentIndex - 1;
	    } 
    	    if (parentIndex > -1 && that.data[parentIndex] != null){ 
		childrenData = that.data[parentIndex][that.childrenDataProp];
	    }
	    print(childrenData, this.childSelectionId, this.childItemIdProp, this.childItemTextProp, currentValue, this.childrenFirstItemText);
	}
	function print(data, selectionId, idProp, textProp, currentValue, firstItemText){
	    var sel = document.getElementById(selectionId);
	    sel.length=0;
	    if (firstItemText != null) {
		sel.options[0] = new Option(firstItemText, null);
	    }
	    var selectedIndex = -1;
	    for (var i = 0; i < data.length; i++) {
		sel.options[sel.length] = new Option(data[i][textProp], data[i][idProp]);
		if (currentValue == data[i][idProp]) {
		    selectedIndex = i;
		}
	    }
	    if (firstItemText != null) {
		selectedIndex = selectedIndex + 1;
	    }
	    sel.selectedIndex = selectedIndex;
	}
	this.test =function(){
		alert('Parent Value: ' + document.getElementById(that.parentSelectionId).value);
		alert('Children Value: ' + document.getElementById(that.childSelectionId).value);
	}
}
</script>
<body>
<div>
<select id='selParent' name='selparent'>	
</select>
<select id='selChildren' name='selchildren'>	
</select>
<script language='javascript'>
var chainer = new Chainer(statesMalaysia, "selParent", "stateId", "stateName", "cities", "selChildren", "cityId", "cityName");
chainer.init("3", "94");
</script>
</div>
</body>
</html>
